package com.flushbonading.classsystem.entity;

import com.flushbonading.classsystem.constants.StateCode;
import com.flushbonading.classsystem.constants.StateMsg;

import java.io.Serializable;

/**
 * @author zyx 2134208960@qq.com
 * @date 2021/11/7 18:24
 * @since 1.0.0
 */
public class CommonResult<T> implements Serializable {
    /**
     * 状态码
     */
    private Integer status;
    /**
     * 消息
     */
    private String message;
    /**
     * 所传数据
     */
    private T   data;

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    private CommonResult(Integer status, String message, T data) {
        this.status = status;
        this.message = message;
        this.data = data;
    }

    public static CommonResult success(String message, Object data){
        return new CommonResult(StateCode.SUCCESS, message, data);
    }

    public static CommonResult success(Object data){
        return new CommonResult(StateCode.SUCCESS, StateMsg.REQUEST_SUCCESS, data);
    }

    public static CommonResult success(String message){
        return new CommonResult(StateCode.SUCCESS, message, null);
    }

    public static CommonResult error(String message, Object data){
        return new CommonResult(StateCode.ERROR, message, data);
    }

    public static CommonResult error(Object data){
        return new CommonResult(StateCode.ERROR, StateMsg.REQUEST_ERROR, data);
    }

    public static CommonResult error(String message){
        return new CommonResult(StateCode.ERROR, message, null);
    }

    public static CommonResult hasNoAuthoritativeInformation(){
        return new CommonResult(StateCode.NON_AUTHORITATIVE_INFORMATION, StateMsg.NON_AUTHORITATIVE_INFORMATION, null);
    }
}
